USE [Training]
GO

IF NOT EXISTS (SELECT * from dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.training_api_TrainingRecordCompletePending'))
	EXEC('CREATE PROC dbo.training_api_TrainingRecordCompletePending AS')
GO

ALTER PROC dbo.training_api_TrainingRecordCompletePending
	@TrainingRecordID	int,
	@InspectedBy		int,
	@CompletedDate		datetime
AS
	IF (SELECT CompletedDate FROM TrainingRecord WHERE TrainingRecordID = @TrainingRecordID) IS NULL
		UPDATE TrainingRecord
		SET
			InspectedBy = @InspectedBy,
			@CompletedDate = @CompletedDate,
			LastModified = GETDATE()
		WHERE
			TrainingRecordID = @TrainingRecordID
	ELSE 
		RAISERROR('Cannot re-sign a closed training item.',11,1)

